How does bitwise AND (&) work when applied to two binary numbers?
How does bitwise AND (&) work when applied to two binary numbers?
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Aryan Kumar
31-Oct-2023The bitwise AND (&) operator in JavaScript is used to perform a bitwise AND operation on the individual bits of two binary numbers. It returns a new number where each bit is set (1) only if the corresponding bits in both input numbers are 1.
Let's take an example to understand how the bitwise AND operator works with binary numbers:
In this example, the AND operation is performed on num1 and num2. The result has a 1 at each position where both input numbers have a 1. So, 5 & 3 results in 1 because the only common bit set to 1 in both binary representations is the 2^0 position.
The bitwise AND operator is often used in programming to mask or isolate specific bits within a number, perform bit-level tests, or clear (set to 0) certain bits in a binary representation.